<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function fn(N,M) {
                return Math.floor(Math.random() * (M-N+1))+N
        }
            let n=fn(1,10)
            while(true)
            {
                let num=+prompt('请输入一个数字')
                
            if (num > n) {
                alert('数字猜大了')
            }
            else if(num < n) {
                alert('数字猜小了')

            }
            else if(n==num) {
                alert('数字猜对了')
                break
            }
        }
        fn()

    </script>
</body>

</html>